﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BellRingers
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public string[] BadEvents = { "Computer Got Hacked", "Struck By Employee Theft", "Computer Physically Broke", 
                                        "Employee Downloaded an Email Virus", "Your Hard Drive Just Crashed",
                                    "Employee Downloaded Bad Stuff", "Nothing Happened - Amazing"};

        private string[] towers = { "Joe's Virus Protection - Cost $100", "Paul's Virus Protection - Cost $50", "Bobby V's Virus Protection - Cost $0", 
                                      "Joe's Firewall - Cost $100",
                                  "Paul's Firewall - Cost $50", "Bobby V's Firewall - Cost $0", "Employee Training - email - Cost $100",
                                  "Employee Training - Downloading - Cost $100", "Physically LockDown Computers - Cost $150",
                                   "Employees do own backups - Cost $50", "Remote Offsite auto backups - Cost $300", "Extended Warrenty - Cost $150",
                                  "Joe's Spyware - Cost $100", "Paul's Spyware - Cost $50", "Bobby V's Spyware - Cost $0"};
        private string[] ringingMethods = { "aJoe's Protection", "Paul's Protection", "Bob's Protection"};
        public int Turn = 1;
        public int Money = 5000;
        public int cost;
        public int randomNumber;
        public int MoneyThisTurn;
        String MoneySaved;

        //change according to # of bad events
        public int[] randomCheck = new int[7] { 0, 0, 0, 0, 0, 0, 0 };
        //change to how much each bad thing will cost you
        public int[] BadEventMoney = new int[7] { -500, -2000, -2000, -400, -1000, -400, 0};
        //associate good events with the bad events
        public int[] GoodVSBad = new int[15] { 3, 3, 3, 0, 0, 0, 3, 5, 1, 4, 4, 2, 5, 5, 5 };
        //Change to what each good thing saves you
        public int[] GoodEventMoney = new int[15] { 400, 200, 5, 500, 250, 5, 200, 200, 2000, 200, 1000, 2000, 400, 200, 5};
        //on/off switch for good events
        public int[] GoodEventCheck = new int[15] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        //cost of items for good events
        public int[] GoodEventCost = new int[15] { 100, 50, 0, 100, 50, 0, 100, 100, 150, 50, 300, 150, 100, 50, 0 };
        public int GoodEventArrayNumber;

        public Window1()
        {
            InitializeComponent();
            this.Reset();
        }

        public void Reset()
        {
            
            firstName.Text = "" + Money;
            lastName.Text = "Week " + Turn;
            previousChoices.Text = "Your Previous Choices: \n";
            badChoices.Text = "Previous Bad Events: \n";

            towerNames.Items.Clear();
            foreach (string towerName in towers)
            {
                towerNames.Items.Add(towerName);
            }
            towerNames.Text = towerNames.Items[0] as string;
            
            //methods.Items.Clear();
            //CheckBox method;
            //foreach (string methodName in ringingMethods)
            //{
            //    method = new CheckBox();
            //    method.Margin = new Thickness(0, 0, 0, 10);
            //    method.Content = methodName;
            //    methods.Items.Add(method);
            //}

            

            //novice.IsChecked = true;

            
        }

        private void clear_Click(object sender, RoutedEventArgs e)
        {
            this.Reset();
        }

        private void add_Click(object sender, RoutedEventArgs e)
        {
            //create a random event
            MoneyThisTurn = 0;
            MoneySaved = "Choices that helped this round and thier savings.\n";

            Random randomBadEvent = new Random();

            //change to number of bad events
            randomNumber = randomBadEvent.Next(7);

            while (randomCheck[randomNumber] == 1)
            {
                //change to number of bad events
                randomNumber = randomBadEvent.Next(7);
            }

            randomCheck[randomNumber] = 1;
            Turn = Turn + 1;

            //change for to represent # of good edvents
            for (int i = 0; i < 15; i++)
            {
                if (towers[i] == towerNames.Text)
                {
                    GoodEventArrayNumber = i;
                    GoodEventCheck[GoodEventArrayNumber] = 1;
                    cost = GoodEventCost[GoodEventArrayNumber];
                }
            }

            MoneyThisTurn = MoneyThisTurn + BadEventMoney[randomNumber] - cost;

            switch (randomNumber)
            {
               //{ 3, 3, 3, 0, 0, 0, 3, 5, 1, 4, 4, 2, 5, 5, 5 };

                case 0:
                    if (GoodEventCheck[3] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[3];
                        MoneySaved = MoneySaved + "     Joe's Firewall Saved you " + " $" + GoodEventMoney[3] + "\n";
                    }
                    if (GoodEventCheck[4] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[4];
                        MoneySaved = MoneySaved + "     Paul's Firewall saved you " + " $" + GoodEventMoney[4] + "\n";
                    } 
                    if (GoodEventCheck[5] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[5];
                        MoneySaved = MoneySaved + "     Booby V's Firewall saved you " + " $" + GoodEventMoney[5] + "\n";
                    } 
                    break;
                case 1:
                    if (GoodEventCheck[8] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[8];
                        MoneySaved = MoneySaved + "     Physically Locking Down saved you " + " $" + GoodEventMoney[8] + "\n";
                    }
                    break;
                case 2:
                    if (GoodEventCheck[11] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[11];
                        MoneySaved = MoneySaved + "     Extended Warrenty saved you " + " $" + GoodEventMoney[11] + "\n";
                    } 
                    break;
                case 3:
                    if (GoodEventCheck[0] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[0];
                        MoneySaved = MoneySaved + "     Joe's Virus Protection saved you " + " $" + GoodEventMoney[0] + "\n";
                    } 
                    if (GoodEventCheck[1] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[1];
                        MoneySaved = MoneySaved + "     Paul's Virus Protection saved you " + " $" + GoodEventMoney[1] + "\n";
                    } 
                    if (GoodEventCheck[2] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[2];
                        MoneySaved = MoneySaved + "     Booby V's Virus Protection saved you " + " $" + GoodEventMoney[2] + "\n";
                    } 
                    if (GoodEventCheck[6] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[6];
                        MoneySaved = MoneySaved + "     Employee Training - Email saved you " + " $" + GoodEventMoney[6] + "\n";
                    }
                    break;
                case 4:
                    if (GoodEventCheck[9] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[9];
                        MoneySaved = MoneySaved + "     Employees doing own Backups saved you " + " $" + GoodEventMoney[9] + "\n";
                    }
                    if (GoodEventCheck[10] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[10];
                        MoneySaved = MoneySaved + "     Remote Offsite Backup saved you " + " $" + GoodEventMoney[10] + "\n";
                    }
                    break;
                case 5:
                    if (GoodEventCheck[7] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[7];
                        MoneySaved = MoneySaved + "     Employee Training - Downloading saved you " + " $" + GoodEventMoney[7] + "\n";
                    }
                    if (GoodEventCheck[12] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[12];
                        MoneySaved = MoneySaved + "     Joe's Spyware saved you " + " $" + GoodEventMoney[12] + "\n";
                    }
                    if (GoodEventCheck[13] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[13];
                        MoneySaved = MoneySaved + "     Paul's Spyware saved you " + " $" + GoodEventMoney[13] + "\n";
                    }
                    if (GoodEventCheck[14] == 1)
                    {
                        MoneyThisTurn = MoneyThisTurn + GoodEventMoney[14];
                        MoneySaved = MoneySaved + "     Bobby V's Spyware saved you " + " $" + GoodEventMoney[14] + "\n";
                    }
                    break;
                case 6:
                    break;

            }

            MoneyThisTurn = MoneyThisTurn + 1000;

            string nameAndTower = String.Format("Thats it for week " + (Turn - 1) + "\n\n"
                + BadEvents[randomNumber] + " Which cost you $" + BadEventMoney[randomNumber] + "\n\n"
                + "This week you chose to implement " + towerNames.Text + "" + "\n\n" + MoneySaved + "\n"
                + "Pass GO - Collect profits of $1000 \n\n" 
             + "Overall, this turn - given everything - your money has changed $" + MoneyThisTurn);
            Money = Money + MoneyThisTurn;
            firstName.Text = "" + Money;
            lastName.Text = "Week " + Turn;
            previousChoices.Text = previousChoices.Text + (Turn - 1) + " " + towerNames.Text + "\n";
            badChoices.Text = badChoices.Text + (Turn - 1) + " " + BadEvents[randomNumber] + "\n";

            StringBuilder details = new StringBuilder();
            details.AppendLine(nameAndTower);
           // foreach (CheckBox cb in methods.Items)
           // {
           //     if (cb.IsChecked.Value)
           //     {
           //         details.AppendLine(cb.Content.ToString());
           //     }
           // }
            MessageBox.Show(details.ToString(), "Member Information");
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            MessageBoxResult key = MessageBox.Show(
                "Are you sure you want to quit",
                "Confirm", 
                MessageBoxButton.YesNo,
                MessageBoxImage.Question,
                MessageBoxResult.No);
            e.Cancel = (key == MessageBoxResult.No);
        }

        private void towerNames_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void previousChoices_TextChanged(object sender, TextChangedEventArgs e)
        {

        }




    }
}
